package com.woniuxy.service.impl;

import com.woniuxy.dao.PermDao;
import com.woniuxy.entity.Perm;
import com.woniuxy.entity.ResponseEntity;
import com.woniuxy.service.PermService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import java.util.List;

/**
 * @Author：jojo
 * @Date：2022/3/8 14:50
 * @Description :TODO
 */
@Service
public class PermServiceImpl implements PermService {

    @Autowired(required = false)
    PermDao permDao;
    /*
     *功能描述  添加新权限
     * @Author: jojo
     * @Date: 2022/3/8 14:51
     * @param perm
     * @return com.woniuxy.entity.ResponseEntity
     */
    @Override
    public ResponseEntity addPerm(Perm perm) {
        int num = permDao.addPerm(perm);
        if (num>0){
            return ResponseEntity.success("添加成功");
        }else {
            return ResponseEntity.error("系统维护中....");
        }
    }

    @Override
    public ResponseEntity deletPerm(int id) {
        int num = permDao.delet(id);
        if (num>0){
            int num2 = permDao.deletO(id);
            return ResponseEntity.success("删除成功");
        }else {
            return ResponseEntity.error("系统维护中....");
        }
    }

    @Override
    public ResponseEntity update(Perm perm) {
        int num = permDao.update(perm);
        if (num>0){
            return ResponseEntity.success("修改成功");
        }else {
            return ResponseEntity.error("系统维护中....");
        }
    }

    @Override
    public ResponseEntity findAll() {
        List<Perm> list = permDao.findAll();
        if (list!=null){
            return ResponseEntity.success("查询成功",list);
        }else {
            return ResponseEntity.error("系统维护中....");
        }
    }

    @Override
    public ResponseEntity findPerm(int roleid) {
        List<Integer> list = permDao.findPerm(roleid);
        System.out.println(list.toString());
        if (list.size()>0){
            List<Perm> list2 = permDao.findPerms(list);
            if (list2.size()>0){
                return ResponseEntity.success("成功",list2);
            }else {
                return ResponseEntity.error("系统维护中....");
            }
        }else {
            List<Perm> all = permDao.findAll();
            return ResponseEntity.success("- -",all);
        }
    }

    @Override
    public ResponseEntity findPerm1(int roleid) {
        List<Integer> list = permDao.findPerm(roleid);
        System.out.println(list.toString());
        if (list.size()>0){
            List<Perm> list2 = permDao.findPerms1(list);
            if (list2.size()>0){
                return ResponseEntity.success("成功",list2);
            }else {
                return ResponseEntity.error("系统维护中....");
            }
        }else {
            return ResponseEntity.success("- -",null);
        }
    }
}
